// pages/tuijian1/tuijian1.js
const util = require('../../utils/util.js')
import Bmob from '../../utils/dist/Bmob-1.7.0.min.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showModal: false,
    showModal: false,
    showModal2: false,
    showModal3: false,
    showModal4: false,
    showModal5: false,


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var xqsj = []
    var shuju = JSON.parse(options.shuju);
    // console.log(options.shuju,"45")
    //var shuju = options.shuju
    this.setData({
      shuju: shuju
    })
    var imgPic = []
    var imgPic1 = []
    var content2 = []
    for (var i = 0; i < 1; i++) {
      imgPic1.push(shuju.pic)
    }
    for (var i = 0; i < shuju.process.length; i++) {
      imgPic.push(shuju.process[i].pic)
      content2.push(shuju.process[i].pcontent.replace("<br />", ""))

    }
    this.setData({
      content2: content2
    })
    this.setData({
      imgPic1: imgPic1
    })
    this.setData({
      imgPic: imgPic
    })


  },
  removeChars: function (source, chars) {            //正则去掉<br />符号
    console.log(this.data.source)
    var reg = new RegExp(chars, 'gi');
    var result1 = this.data.source.replace(reg, "");
    return result1;
  },
  previewImage: function (e) {   //图片显示
    wx.previewImage({
      current: e.target.dataset.src,
      urls: this.data.imgPic
    })
  },
  previewImage1: function (e) {    //图片显示
    wx.previewImage({
      current: e.target.dataset.src,
      urls: this.data.imgPic1
    })
  },
  funSave: function () {    //保存

    
  },
  funLike: function () {     //推荐
    const query = Bmob.Query('hyh');
    query.set("dataId", Number(this.data.shuju.id))
    query.set("classid",this.data.shuju.classid )
    query.set("content",this.data.shuju.content)
    query.set("material",this.data.shuju.material)
    query.set("process",this.data.shuju.process)
    query.set("tag",this.data.shuju.tag)
    query.set("pic01",this.data.imgPic1)
    query.set("watch",30)
    query.set("name",this.data.shuju.name)
    query.set("time",this.data.shuju.cookingtime)
    query.set("people",this.data.shuju.peoplenum)
    query.save().then(res => {

      wx.showToast({      //推荐成功提示图
        title: '推荐成功',
        icon: 'success',
        duration: 3000
      });
      
      console.log(res)
    }).catch(err => {
      console.log(err)
    })

  },
  // 弹出层里面的弹窗
  ok: function () {
    this.setData({
      showModal: false,
      showModal1: false,
      showModal2: false,
    })
  },
  ok1: function () {
    this.setData({
      showModal3: false,
      showModal4: false,
      showModal5: false,
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})